package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class TestServlet extends HttpServlet {

	/*
	* 1、用于发送请求
	* 2、web容器根据用户请求，解析web.xml文件
	* 3、根据url-pattern匹配用户请求的路径，web容器根据servlet-class 类的完全限定名==》实例化类
	* 4、执行初始化init方法
	* 5、执行service方法，根据用户请求的方式【get/post】,决定调用doGet / doPost来处理用户请求
	* 6、将请求结果响应到客户端
	* 7、由web容器调用destroy方法对servlet类进行销毁
	* */

	public TestServlet(){
		System.out.println("实例化TestServlet");
	}

	@Override
	public void init() throws ServletException {
		System.out.println("初始化init");
		super.init();
	}

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("service");
		super.service(req, resp);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doPost");

	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doGet");
	}

	@Override
	public void destroy() {
		System.out.println("销毁");
		super.destroy();
	}
}
